// 查询用户是否登录
function loginUser() {
  const token = localStorage.getItem("token");
  console.log(token);
  axios
    .get("http://127.0.0.1:3000/api/v1/user/userInfo", {
      headers: {
        authorization: token,
        "Content-Type": "application/json", // 如果发送的是JSON数据，设置这个头部
      },
    })
    .then(function (res) {
      console.log(res);
      if (res.status == 200) {
        if (res.data.code == 0) {
          const userImg = document.getElementsByClassName("userImg")[0];
          const username = document.getElementsByClassName("username")[0];

          userImg.style.backgroundImage = `url(${res.data.data.img})`;
          username.innerHTML = res.data.data.username;
        } else {
          window.location.href = "../backEnd/loginAndRegister.html";
        }
      } else {
        window.location.href = "../backEnd/loginAndRegister.html";
      }
    })
    .catch(function (error) {
      console.log(error);
      window.location.href = "../backEnd/loginAndRegister.html";
    });
}
loginUser();
// 导航栏点击对应页面跳转
// 跳转首页
function home() {
  window.location.href = "../front/home3.html";
}
// 跳转iframe
function iframe(e) {
  e.stopPropagation();
  let iframe = document.getElementsByClassName("iframe")[0];
  iframe.src = e.target.dataset.iframe;
}

// 退出登录
function mouseenter() {
    let loginOut = document.getElementsByClassName("loginOut")[0];
    loginOut.style.display = "block";
}

function mouseleave() {
    let loginOut = document.getElementsByClassName("loginOut")[0];
    loginOut.style.display = "none";
}

function goBackLogin() {
    localStorage.removeItem('token');
    loginUser()
}